package cai.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.IOException;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;

public class CaiTest {
	
	public static final String pathDaFa = "D:/cai/2024-08-19/大发pk10/";
	public static final String path1FenSaiChe = "D:/cai/2024-08-19/1分赛车/";

	
	@Test
	public void testAS5() throws Exception {
		//execute8AS5(4+"", pathDaFa + "18.11.txt", null);
		for (int i = 0; i < 10; i++) {
			
			/* 固定5位不开、pk10			 
			 大发PK10		08:11:05	5,3,9,4,1,7,10,6,8,2	本期：2		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/大发pk10/09.09.txt	数字：3		 num: 9,9点转3
			 大发PK10		09:55:05	1,9,8,7,6,3,10,5,2,4	本期：4		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/大发pk10/11.51.txt	数字：9		 num: 11，10点转9
			 大发PK10		11:01:04	8,4,1,3,7,10,2,9,6,5	本期：2		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/大发pk10/11.51.txt	数字：1		 num: 8，11点转1
			 大发PK10		11:38:05	4,10,9,8,2,6,5,7,1,3	本期：2		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/大发pk10/11.51.txt	数字：5		 num: 12，12点转5
			 大发PK10		13:57:04	10,6,9,1,4,3,7,8,2,5	本期：4		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/大发pk10/14.12.txt	数字：4		 num: 9，14点转4
			 大发PK10		14:41:04	9,6,10,7,5,4,2,3,8,1	本期：3		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/大发pk10/15.08.txt	数字：6		 num: 12，15点转6
			 大发PK10		15:53:04	5,2,8,3,6,4,1,9,10,7	本期：3		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/大发pk10/18.11.txt	数字：4		 num: 9，16点转4
			 大发PK10		16:30:06	2,10,5,7,8,6,4,9,1,3	本期：7		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/大发pk10/18.11.txt	数字：4		 num: 8, 17点转4
			 大发PK10		17:27:05	6,1,7,3,9,5,2,4,10,8	本期：9		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/大发pk10/18.11.txt	数字：6		 num: 13，18点转6
			*/
			
			execute8AS5((i+1)+"", pathDaFa + "18.11.txt", null);
			
			/*
			 1分赛车		08:54:04	3,9,7,8,1,2,4,5,6,10	本期：4		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/1分赛车/09.09.txt	数字：3		 num: 9, 9点转3
			 1分赛车		14:42:04	5,4,7,8,9,2,1,3,10,6	本期：2		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/1分赛车/15.08.txt	数字：1		 num: 12，15点转1
			 1分赛车		15:53:04	3,2,9,5,8,7,6,4,1,10	本期：9		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/1分赛车/16.06.txt	数字：5		 num: 8，16点转5
			 1分赛车		16:55:05	8,7,9,10,3,2,1,4,5,6	本期：3		固定4：[2, 3, 4, 7, 9]	D:/cai/2024-08-19/1分赛车/17.02.txt	数字：8		 num: 8，17点转8
			*/
			//execute8AS5((i+1)+"", path1FenSaiChe + "18.11.txt", null);
			
			
		}
		
		
	}
	
	
	@Test
	public void test1() throws Exception {
		for (int i = 0; i < 10; i++) {
			/* 固定4位不开
			 大发PK10		04:52:04	9,5,1,4,8,7,3,6,2,10	本期：9		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/07.41.txt	数字：1		 num: 5，5点转1
			 大发PK10		05:27:04	6,2,3,1,9,8,10,4,7,5	本期：9		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/07.41.txt	数字：8		 num: 8，6点转8
			 大发PK10		06:49:05	7,5,2,9,8,4,3,1,6,10	本期：9		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/07.41.txt	数字：10		 num: 6，7点转10
			 大发PK10		07:29:06	8,5,10,2,3,4,1,6,9,7	本期：2		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/07.41.txt	数字：3		 num: 6，8点转3
			 大发PK10		08:58:06	6,7,5,8,9,2,3,1,4,10	本期：4		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/09.06.txt	数字：8		 num: 6，9点转8
			 大发PK10		09:54:05	1,8,6,5,4,9,10,3,7,2	本期：9		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/11.17.txt	数字：7		 num: 6, 10点转6
			 大发PK10		10:02:05	7,2,3,8,6,1,5,4,10,9	本期：4		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/11.17.txt	数字：2		 num: 6，11点转2
			 大发PK10		11:23:03	9,4,3,2,8,1,10,7,5,6	本期：4		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/13.03.txt	数字：9		 num: 9，12点转9
			 大发PK10		12:39:05	5,6,10,3,2,8,9,1,7,4	本期：7		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/13.03.txt	数字：10		 num: 8，13点转10
			 大发PK10		13:25:05	3,9,8,7,10,2,5,6,1,4	本期：4		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/14.06.txt	数字：1		 num: 10，14点转1
			 大发PK10		14:04:04	5,3,7,2,4,6,1,8,10,9	本期：4		固定4：[2, 4, 7, 9]	E:/cai/dafa2024-08-16/15.00.txt	数字：10		 num: 5，15点转10
			*/
			
			//execute8((i+1)+"", pathDaFa + "07.41.txt");
			//execute8((i+1)+"",  pathDaFa + "09.06.txt");
			//execute8((i+1)+"",  pathDaFa + "11.17.txt");
			//execute8((i+1)+"", pathDaFa + "13.03.txt");
			//execute8((i+1)+"", pathDaFa + "14.06.txt");
			//execute8((i+1)+"", pathDaFa + "15.00.txt");
			//execute8((i+1)+"", pathDaFa + "18.11.txt", null);
			
			
			
			/* 固定4位不开、1分赛车
				1分赛车		06:57:06	2,7,4,6,9,8,1,5,3,10	本期：4		固定4：[2, 4, 7, 9]	E:/cai/1分赛车2024-08-16/09.32.txt	数字：4		 num: 5，7点转4
				1分赛车		07:54:06	9,8,3,7,6,10,2,4,1,5	本期：7		固定4：[2, 4, 7, 9]	E:/cai/1分赛车2024-08-16/09.32.txt	数字：7		 num: 5，8点转7
				1分赛车		08:24:03	9,10,5,1,8,6,7,4,3,2	本期：2		固定4：[2, 4, 7, 9]	E:/cai/1分赛车2024-08-16/09.32.txt	数字：2		 num: 7，9点转2
				1分赛车		09:14:04	7,9,10,6,1,3,4,8,5,2	本期：7		固定4：[2, 4, 7, 9]	E:/cai/1分赛车2024-08-16/11.26.txt	数字：10		 num: 5，10点转10
				1分赛车		10:42:06	1,3,6,2,5,10,8,9,4,7	本期：9		固定4：[2, 4, 7, 9]	E:/cai/1分赛车2024-08-16/11.26.txt	数字：8		 num: 6，11点转8
				1分赛车		11:27:03	7,8,10,9,4,1,6,5,2,3	本期：7		固定4：[2, 4, 7, 9]	E:/cai/1分赛车2024-08-16/13.14.txt	数字：6		 num: 7，12点转6
				1分赛车		12:23:04	5,7,9,6,3,1,10,2,4,8	本期：7		固定4：[2, 4, 7, 9]	E:/cai/1分赛车2024-08-16/13.14.txt	数字：3		 num: 6，13点转3
				1分赛车		13:54:05	7,2,5,10,3,1,8,9,6,4	本期：4		固定4：[2, 4, 7, 9]	E:/cai/1分赛车2024-08-16/14.14.txt	数字：2		 num: 5，14点转2
				1分赛车		14:00:06	10,1,2,8,5,3,4,6,7,9	本期：9		固定4：[2, 4, 7, 9]	E:/cai/1分赛车2024-08-16/15.01.txt	数字：8		 num: 6，15点转8
			*/
			//execute8((i+1)+"", path1FenSaiChe + "09.32.txt");
			//execute8((i+1)+"", path1FenSaiChe + "11.26.txt");
			//execute8((i+1)+"", path1FenSaiChe + "13.14.txt");
			//execute8((i+1)+"", path1FenSaiChe + "14.14.txt");
			//execute8((i+1)+"", path1FenSaiChe + "16.21.txt");
			//execute8((i+1)+"", path1FenSaiChe + "20.06.txt", null);
			
			
			
		}
	}
	
	
	
	 public void execute8AS5(String n, String filePath, String time) throws Exception {
	    	JSONArray array = data(filePath);
	    	Integer ben = null; //本期号
	    	
	    	int num = 0;
	        int maxnum = 0; //最高期数保留
	        String maxNumInfo = null;
	        int maxnumCishu = 0;
	    	StringBuilder sb = new StringBuilder();
	    	
	    	List<Integer> l = new ArrayList<>();
	    	l.add(2);l.add(3);l.add(4);l.add(7);l.add(9);
	    	Set<String> s = new HashSet<>();
	    	for (int size = array.size(); size > 0; size--) {
	            sb.delete(0, sb.length());
	            JSONObject o = array.getJSONObject(size-1);
	            String lotteryOpen = o.getString("lotteryOpen");
	            sb.append(o.getString("gameName")).append("\t\t").append(o.getString("openTime")).append("\t").append(lotteryOpen);

	            sb.append("\t本期：").append(ben == null?"":ben).append("\t\t固定4：").append(l).append("\t").append(filePath).append("\t数字：").append(n);
	            
	            if(ben != null) {
	            	if(l.contains(ben)) {
	            		num ++;
	            		if(num > 9 && !s.contains(l.toString())) { //大于期9期的
	                    	s.add(l.toString());
	                    	maxnumCishu ++;
	                    	System.out.println("\n"+sb);
	                    }
	            	}else {
	            		num = 0;
	            		//l.clear();
	            	};
	            	 sb.append("\t\t num: ").append(num);
	            }
	            
	            String[] split = lotteryOpen.split(",");
	            for (int i = 0; i < split.length; i++) {
	            	
	            	//if(l.size() != 4) l.add(Integer.parseInt(split[i]));
	            	
	                if(split[i].equals(n) && size-2 >= 0) {
	                    Integer next = Integer.parseInt(array.getJSONObject(size-2).getString("lotteryOpen").split(",")[i]);
	                    ben = next;
	                    //break;
	                };
	            }
	            
	           // if(num > maxnum && o.getString("openTime").startsWith("20:")) { //&& o.getString("openTime").startsWith("14:")
	            if(num > maxnum) {
	            	if(time != null) {
	            		if(o.getString("openTime").startsWith(time)) {
	            			maxnum = num; //保留最高期
			                maxNumInfo = sb.toString();
	            		};
	            	}else {
	            		maxnum = num; //保留最高期
		                maxNumInfo = sb.toString();
	            	}
	                
	            }
	            //System.out.println(sb);
	    	}
	    	
	    	
	    	System.out.println("最高期：" + maxNumInfo + ",\t 大于9次的出现次数：" + maxnumCishu);
	    }
	
    
    //
    public void execute(String n, String filePath) throws Exception {
        JSONArray array = data(filePath);
        
        StringBuilder sb = new StringBuilder();
        Integer ben = null; //本期号

        int maxnumCishu = 0;
        
        Queue<Integer> queue = new LinkedList<>();

        int num = 0;
        int maxnum = 0; //最高期数保留
        String maxNumInfo = null;
        
        Queue<Integer> queueTemp = new LinkedList<>();
        
        Set<String> s = new HashSet<>();

        int weiShu = 4;
        for (int size = array.size(); size > 0; size--) {
            sb.delete(0, sb.length());
            JSONObject o = array.getJSONObject(size-1);
            String lotteryOpen = o.getString("lotteryOpen");
            sb.append(o.getString("gameName")).append("\t\t").append(o.getString("openTime")).append("\t").append(lotteryOpen);

            sb.append("\t本期号：").append(ben == null?"":ben).append(" \t历史：").append(queue).append("\t").append(filePath).append("\t数字：").append(n);
            
            if(queue.size() == weiShu) {
                if(queue.contains(ben)) {
                    num ++;
                    if(num > 7 && !s.contains(queue.toString())) { //大于期7期的
                    	s.add(queue.toString());
                    	maxnumCishu ++;
                    	System.out.println("\n"+sb);
                    }
                    
                    if(queueTemp.contains(ben)) queueTemp.remove(ben);
                    queueTemp.offer(ben);
                    if(queueTemp.size() > weiShu) queueTemp.poll();
                } else {
                    num = 0;
                    queueTemp.offer(ben);
                    while(!queueTemp.isEmpty()) {
                        Integer queueTempPoll = queueTemp.poll();
                        if (queue.contains(queueTempPoll)) queue.remove(queueTempPoll);
                        queue.offer(queueTempPoll);
                        if (queue.size() > weiShu) queue.poll();
                    }
                   
                }
                sb.append("\t num: ").append(num);
            }else if(ben != null){
                if(queue.contains(ben)) queue.remove(ben);
                queue.offer(ben);
            }
            String[] split = lotteryOpen.split(",");
 
        
            for (int i = 0; i < split.length; i++) {
                if(split[i].equals(n) && size-2 >= 0) {
                    Integer next = Integer.parseInt(array.getJSONObject(size-2).getString("lotteryOpen").split(",")[i]);
                    ben = next;
                    break;
                };
            }
            if(num >= maxnum) {
                maxnum = num; //保留最高期
                maxNumInfo = sb.toString();
                
            }
          
            //System.out.println(sb);
            
        }

        System.out.println("最高期：" + maxNumInfo + ",\t 大于7次的出现次数：" + maxnumCishu);
    }
     

    /**
     * 4码固定
     * (大发1分pk)最高13期才中
     * (1分赛车)最高9期才中
     * (3分赛车)最高5期才中
     * @throws IOException
     */
    @Test
    public void test2() throws Exception {
    	JSONArray array = data("D:/cai/dafa-2024-08-13-17.56.txt");

        Integer ben = null; //本期号

        Queue<Integer> queue = new LinkedList<>();
        Queue<Integer> queueTemp = new LinkedList<>();
        int num = 0;
        int maxnum = 0; //最高期数保留
        String maxNumInfo = null;
        StringBuilder sb = new StringBuilder();
        System.out.println("array.size() = " + array.size());
        for (int size = array.size(); size > 0; size--) {
            sb.delete(0, sb.length());

            JSONObject o = array.getJSONObject(size-1);
            String lotteryOpen = o.getString("lotteryOpen");
            sb.append(o.getString("gameName")).append("\t\t").append(o.getString("openTime")).append("\t").append(lotteryOpen);

            sb.append("\t 本期号：").append(ben == null?"":ben).append(" \t\t 历史：").append(queue);

            if(queue.size() == 4) {
                if(queue.contains(ben)) {
                    num = 0;
                    queueTemp.offer(ben);
                    while(!queueTemp.isEmpty()) {
                        Integer queueTempPoll = queueTemp.poll();
                        if (queue.contains(queueTempPoll)) queue.remove(queueTempPoll);
                        queue.offer(queueTempPoll);
                        if (queue.size() > 4) queue.poll();
                    }
                } else {
                    num ++;
                    if(queueTemp.contains(ben)) queueTemp.remove(ben);
                    queueTemp.offer(ben);
                    if(queueTemp.size() > 4) queueTemp.poll();
                }
                sb.append("\t\t num: ").append(num);
            }else if(ben != null){
                if(queue.contains(ben)) queue.remove(ben);
                queue.offer(ben);
            }
            String[] split = lotteryOpen.split(",");
            for (int i = 0; i < split.length; i++) {
                if(split[i].equals("8") && size-2 >= 0) {
                    Integer next = Integer.parseInt(array.getJSONObject(size-2).getString("lotteryOpen").split(",")[i]);
                    ben = next;
                    break;
                };
            }

            if(num > maxnum) {
                maxnum = num; //保留最高期
                maxNumInfo = sb.toString();
            }
            System.out.println(sb);
        }
        System.out.println("最高期：" + maxNumInfo);
    }

    /**
     * 5码固定、
     * (大发1分pk)最高8期才中
     * (1分赛车)最高9期才中
     * (3分赛车)最高5期才中
     * @throws IOException
     */
    @Test
    public void test5() throws Exception {
        JSONArray array = data("D:/cai/dafa-2024-08-13-17.56.txt");

        Integer ben = null; //本期号

        Queue<Integer> queue = new LinkedList<>();
        Queue<Integer> queueTemp = new LinkedList<>();
        int num = 0;
        int maxnum = 0; //最高期数保留
        String maxNumInfo = null;

        StringBuilder sb = new StringBuilder();
        for (int size = array.size(); size > 0; size--) {
            sb.delete(0, sb.length());

            JSONObject o = array.getJSONObject(size-1);
            String lotteryOpen = o.getString("lotteryOpen");
            sb.append(o.getString("gameName")).append("\t\t").append(o.getString("openTime")).append("\t").append(lotteryOpen);

            sb.append("\t 本期号：").append(ben == null?"":ben).append(" \t\t 历史：").append(queue);

            if(queue.size() == 5) {
                if(queue.contains(ben)) {
                    num = 0;
                    queueTemp.offer(ben);
                    while(!queueTemp.isEmpty()) {
                        Integer queueTempPoll = queueTemp.poll();
                        if (queue.contains(queueTempPoll)) queue.remove(queueTempPoll);
                        queue.offer(queueTempPoll);
                        if (queue.size() > 5) queue.poll();
                    }
                } else {
                    num ++;
                    if(queueTemp.contains(ben)) queueTemp.remove(ben);
                    queueTemp.offer(ben);
                    if(queueTemp.size() > 5) queueTemp.poll();
                }
                sb.append("\t\t num: ").append(num);
            }else if(ben != null){
                if(queue.contains(ben)) queue.remove(ben);
                queue.offer(ben);
            }
            String[] split = lotteryOpen.split(",");
            for (int i = 0; i < split.length; i++) {
                if(split[i].equals("8") && size-2 >= 0) {
                    Integer next = Integer.parseInt(array.getJSONObject(size-2).getString("lotteryOpen").split(",")[i]);
                    ben = next;
                    break;
                };
            }

            if(num > maxnum) {
                maxnum = num; //保留最高期
                maxNumInfo = sb.toString();
            }
            System.out.println(sb);
        }
        System.out.println("最高期：" + maxNumInfo);
    }

    /**
     * 6码固定
     * @throws IOException
     */
    @Test
    public void test6() throws Exception {
        JSONArray array = data("D:/cai/dafa-2024-08-13-17.56.txt");

        Integer ben = null; //本期号

        Queue<Integer> queue = new LinkedList<>();
        Queue<Integer> queueTemp = new LinkedList<>();
        int num = 0;
        int maxnum = 0; //最高期数保留
        String maxNumInfo = null;

        StringBuilder sb = new StringBuilder();
        for (int size = array.size(); size > 0; size--) {
            sb.delete(0, sb.length());

            JSONObject o = array.getJSONObject(size-1);
            String lotteryOpen = o.getString("lotteryOpen");
            sb.append(o.getString("gameName")).append("\t\t").append(o.getString("openTime")).append("\t").append(lotteryOpen);

            sb.append("\t 本期号：").append(ben == null?"":ben).append(" \t\t 历史：").append(queue);

            if(queue.size() == 6) {
                if(queue.contains(ben)) {
                    num = 0;
                    queueTemp.offer(ben);
                    while(!queueTemp.isEmpty()) {
                        Integer queueTempPoll = queueTemp.poll();
                        if (queue.contains(queueTempPoll)) queue.remove(queueTempPoll);
                        queue.offer(queueTempPoll);
                        if (queue.size() > 6) queue.poll();
                    }
                } else {
                    num ++;
                    if(queueTemp.contains(ben)) queueTemp.remove(ben);
                    queueTemp.offer(ben);
                    if(queueTemp.size() > 6) queueTemp.poll();
                }
                sb.append("\t\t num: ").append(num);
            }else if(ben != null){
                if(queue.contains(ben)) queue.remove(ben);
                queue.offer(ben);
            }
            String[] split = lotteryOpen.split(",");
            for (int i = 0; i < split.length; i++) {
                if(split[i].equals("8") && size-2 >= 0) {
                    Integer next = Integer.parseInt(array.getJSONObject(size-2).getString("lotteryOpen").split(",")[i]);
                    ben = next;
                    break;
                };
            }

            if(num > maxnum) {
                maxnum = num; //保留最高期
                maxNumInfo = sb.toString();
            }
            System.out.println(sb);
        }
        System.out.println("最高期：" + maxNumInfo);
    }
    
    
    //最高10期才中， dafa-2024-08-13-17.56.txt ，数字5，对比1小时前
    @Test
    public void test7() throws Exception {
    	JSONArray array = data("D:/cai/dafa-2024-08-13-17.56.txt");
    	
    	int b = 5;
    	
    	Map<String, String[]> m = new HashMap<>();
    	for (int i = 0; i < array.size(); i++) {
    		 JSONObject o = array.getJSONObject(i);
    		 String openTime = o.getString("openTime").substring(0, 5);
             String lotteryOpen = o.getString("lotteryOpen");
             m.put(openTime, lotteryOpen.split(","));
    	}
    	
    	int num = 0;
        int maxnum = 0; //最高期数保留
        String maxNumInfo = null;
    	
    	DateTimeFormatter of = DateTimeFormatter.ofPattern("HH:mm");
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < array.size(); i++) {
    		 sb.delete(0, sb.length());
    		 JSONObject o = array.getJSONObject(i);
    		 if(i == 0) {
    			 System.out.println(o.getString("gameName"));
    		 }

    		 String openTime = o.getString("openTime").substring(0, 5);
             String lotteryOpen = o.getString("lotteryOpen");
             
             String laOpenTime = LocalTime.parse(openTime, of).minusHours(1).format(of);
             sb.append(openTime).append("\t").append(lotteryOpen).append("\t 一小时前：").append(laOpenTime).append("\t");
             
             if(m.containsKey(laOpenTime)) {
            	 
            	 String ben = Integer.parseInt(lotteryOpen.split(",")[b-1]) <= 5? "小": "大";
            	 String la = Integer.parseInt(m.get(laOpenTime)[b-1]) <= 5? "小": "大";
            	 
            	 if(ben.equals(la)) {
            		 sb.append("中\t ").append(Arrays.asList(m.get(laOpenTime)));
            		 num = 0;
            	 } else {
            		 num ++;
            		 sb.append("否\t").append(Arrays.asList(m.get(laOpenTime)));
            	 }
             }
             

             if(num > maxnum) {
                 maxnum = num; //保留最高期
                 maxNumInfo = sb.toString();
             }
             
             System.out.println(sb);
    	}
    	
    	System.out.println("最高期：" + maxNumInfo + ", num:" + maxnum);
    }
    
    
    //
    
   
   
    public void execute8(String n, String filePath,String time) throws Exception {
    	JSONArray array = data(filePath);
    	Integer ben = null; //本期号
    	
    	int num = 0;
        int maxnum = 0; //最高期数保留
        String maxNumInfo = null;
        int maxnumCishu = 0;
    	StringBuilder sb = new StringBuilder();
    	
    	List<Integer> l = new ArrayList<>();
    	l.add(2);l.add(4);l.add(7);l.add(9);
    	Set<String> s = new HashSet<>();
    	for (int size = array.size(); size > 0; size--) {
            sb.delete(0, sb.length());
            JSONObject o = array.getJSONObject(size-1);
            String lotteryOpen = o.getString("lotteryOpen");
            sb.append(o.getString("gameName")).append("\t\t").append(o.getString("openTime")).append("\t").append(lotteryOpen);

            sb.append("\t本期：").append(ben == null?"":ben).append("\t\t固定4：").append(l).append("\t").append(filePath).append("\t数字：").append(n);
            
            if(ben != null) {
            	if(l.contains(ben)) {
            		num ++;
            		if(num > 7 && !s.contains(l.toString())) { //大于期7期的
                    	s.add(l.toString());
                    	maxnumCishu ++;
                    	System.out.println("\n"+sb);
                    }
            	}else {
            		num = 0;
            		//l.clear();
            	};
            	 sb.append("\t\t num: ").append(num);
            }
            
            String[] split = lotteryOpen.split(",");
            for (int i = 0; i < split.length; i++) {
            	
            	//if(l.size() != 4) l.add(Integer.parseInt(split[i]));
            	
                if(split[i].equals(n) && size-2 >= 0) {
                    Integer next = Integer.parseInt(array.getJSONObject(size-2).getString("lotteryOpen").split(",")[i]);
                    ben = next;
                    //break;
                };
            }
            
            if(num > maxnum) {
            	if(time != null) {
            		if(o.getString("openTime").startsWith(time)) {
            			maxnum = num; //保留最高期
		                maxNumInfo = sb.toString();
            		};
            	}else {
            		maxnum = num; //保留最高期
	                maxNumInfo = sb.toString();
            	}
                
            }
            //System.out.println(sb);
    	}
    	
    	
    	System.out.println("最高期：" + maxNumInfo + ",\t 大于7次的出现次数：" + maxnumCishu);
    }
    
    public static JSONArray data(String filePath) throws Exception {
    	FileInputStream fileInputStream = new FileInputStream(filePath);
        StringBuilder sb = new StringBuilder();
        byte[] buf = new byte[1024*10];
        while(fileInputStream.read(buf) != -1) sb.append(new String(buf,"utf-8"));
        fileInputStream.close();
        String jsonStr = sb.toString().replaceAll("\\s*|\t|\r|\n", "");
        return JSON.parseObject(jsonStr).getJSONObject("data").getJSONObject("backData").getJSONArray("lotteryOpen");
    }

}
